//
//  TJBindingPhoneController.m
//  BaoDian
//
//  Created by mac on 2024/7/23.
//

#import "TJBindingPhoneController.h"
#import "TJTitleTextField.h"
#import "QMUIButton.h"
#import "TJStyle1Button.h"


@interface TJBindingPhoneController ()

@property (nonatomic, weak) TJTitleTextField *phoneTextField;
@property (nonatomic, weak) TJTitleTextField *codeTextField;
@property (nonatomic, weak) TJStyle1Button *confirmButton;


@end

@implementation TJBindingPhoneController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    UIScrollView *scrollView = [UIScrollView addToView:self.view];
    scrollView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
    CGSize contentSize = scrollView.bounds.size;
    scrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    scrollView.contentSize = contentSize;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.alwaysBounceVertical = YES;
    scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    
    UIView *contentView = [[UIView alloc] init].addTo(scrollView);
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
        make.width.offset(contentSize.width);
        make.height.offset(contentSize.height);
    }];
        
    UILabel *titleLabel = [UILabel lableWithSuperView:contentView font:UIFontBoldMake(24) color:UIColor.whiteColor title:@"绑定手机" textAlignment:NSTextAlignmentLeft];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(KStatusBarHight + 80);
        make.left.offset(32);
    }];
    
    UILabel *subTitleLabel = [UILabel lableWithSuperView:contentView font:UIFontMake(14) color:UIColor.whiteColor title:@"请绑定本人持有的支付宝账号" textAlignment:NSTextAlignmentLeft];
    subTitleLabel.numberOfLines = 0;
    [subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLabel.mas_bottom).offset(8);
        make.left.equalTo(titleLabel);
        make.right.inset(leftRightMargin);
    }];
    
    TJTitleTextField *phoneTextField = [TJTitleTextField addToView:contentView];
    phoneTextField.titleLabel.text = @"手机号码";
    phoneTextField.textField.placeholder = @"*请输入您的手机号";
    phoneTextField.addCornerRadius(25);
    phoneTextField.textField.attributedPlaceholder = [phoneTextField.textField.placeholder attributedStringWithRangeString:@"*" rangeColor:UIColorMake(0xEF382D) color:UIColor.tj_placeholderTextColor];
    phoneTextField.backgroundColor = UIColor.tj_1E1F23Color;
    phoneTextField.textField.keyboardType = UIKeyboardTypeASCIICapable;
    [phoneTextField.textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    phoneTextField.textField.maximumTextLength = 11;
    [phoneTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(32);
        make.top.equalTo(titleLabel.mas_bottom).offset(60);
        make.height.offset(50);
    }];
    
    TJTitleTextField *codeTextField = [TJTitleTextField addToView:contentView];
    codeTextField.titleLabel.text = @"验证码";
    codeTextField.textField.placeholder = @"*请输入验证码";
    codeTextField.addCornerRadius(25);
    codeTextField.textField.attributedPlaceholder = [codeTextField.textField.placeholder attributedStringWithRangeString:@"*" rangeColor:UIColorMake(0xEF382D) color:UIColor.tj_placeholderTextColor];
    codeTextField.backgroundColor = UIColor.tj_1E1F23Color;
    codeTextField.textField.keyboardType = UIKeyboardTypeASCIICapable;
    [codeTextField.textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    codeTextField.textField.maximumTextLength = 12;
    [codeTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(phoneTextField);
        make.top.equalTo(phoneTextField.mas_bottom).offset(16);
    }];
    
    QMUIButton *sendCodeButton = [QMUIButton buttonWithSuperView:codeTextField font:UIFontMake(14) color:UIColorMake(0x2978F0) title:@"获取验证码"];
    [sendCodeButton addTarget:self action:@selector(didClickSendCodeButton) forControlEvents:UIControlEventTouchUpInside];
    [sendCodeButton sizeToFit];
    [sendCodeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.inset(20);
        make.height.offset(sendCodeButton.tj_size.height);
        make.width.offset(sendCodeButton.tj_size.width);
        make.centerY.offset(0);
    }];
    
    TJStyle1Button *confirmButton = [TJStyle1Button buttonWithSuperView:contentView font:UIFontMediumMake(16) color:nil title:@"确认绑定"];
    confirmButton.enabled = NO;
    [confirmButton addTarget:self action:@selector(didClickConfirmButton) forControlEvents:UIControlEventTouchUpInside];
    [confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(leftRightMargin);
        make.height.offset(buttonHeight);
        make.top.equalTo(codeTextField.mas_bottom).offset(46);
    }];
    
    _phoneTextField = phoneTextField;
    _codeTextField = codeTextField;
    _confirmButton = confirmButton;
}

- (void)didClickConfirmButton {
    
    
}

- (void)didClickSendCodeButton {
    
    
}

- (void)textFieldDidChange:(UITextField *)textField {
    _confirmButton.enabled = !isEmptyString(_phoneTextField.textField.text) &&  !isEmptyString(_codeTextField.textField.text);
}
 

- (UIImage *)topBackgroundImage {
    return [UIImage imageNamed:@"loginTopBackground"];
}

 
@end
